package cn.tianyigps.m7.netty;


import io.netty.channel.ChannelInitializer;
import io.netty.handler.logging.LogLevel;
import io.netty.handler.logging.LoggingHandler;
import io.netty.handler.timeout.IdleStateHandler;

import java.util.concurrent.TimeUnit;

public class TCPServerChannelInitalizer extends ChannelInitializer<TYNioSocketChannel> {
    @Override
    public void initChannel(TYNioSocketChannel ch) {
        // 处理日志
        TYChannelPipeline pipeline = (TYChannelPipeline) ch.pipeline();
        pipeline.addLast(new LoggingHandler(LogLevel.INFO));
        // 处理心跳
        pipeline.addLast(new IdleStateHandler(1800, 0, 1800, TimeUnit.SECONDS));
        pipeline.addLast(new ChatHeartbeatHandler());
        // 设备回复
        pipeline.addLast(new EquipmentDecoder());
        // 数据解析
        pipeline.addLast(new EquipmentHandler());
    }
}